//
//  UIWindow+Extension.m
//  CoachAssistant
//
//  Created by XCY–hqF on 16/5/18.
//  Copyright © 2016年 XCY. All rights reserved.
//

#import "UIWindow+Extension.h"
#import "DSAccountViewModel.h"
#import "MTNavigationController.h"
#import "DSHomeController.h"
#import "DSNotLoggedSelectController.h"
#import "AppDelegate.h"
#import "UIStoryboard+Extension.h"

@implementation UIWindow (Extension)

+ (void)switchRootVCToAppDelegateWin
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [self switchRootViewControllerWithWindow:appDelegate.window];
}

- (void)switchRootViewController
{
    [UIWindow switchRootViewControllerWithWindow:self];
}

+ (void)switchRootViewControllerWithWindow:(UIWindow *)window
{
    DSAccount *account = [DSAccountViewModel sharedAccount].account;
    NSString *token = account.stuId;
    if (token != nil && token.length > 0) {  //已登录
        
        //初始化rootVC
        MTNavigationController *navigationCtrl = [[MTNavigationController alloc] initWithRootViewController:[[DSHomeController alloc] init]];
        window.rootViewController = navigationCtrl;
    }else{   //未登录
        DSNotLoggedSelectController *loginVC = (DSNotLoggedSelectController *)[UIStoryboard initialVCWithName:@"DSNotLoggedSelectController"];
        loginVC.title = @"登录";
        MTNavigationController *navi = [[MTNavigationController alloc] initWithRootViewController:loginVC];
        window.rootViewController = navi;
    }
}

+ (void)appSwitchRootViewControllerWithVC:(UIViewController *)vc
{
    AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
    appDelegate.window.rootViewController = vc;
}

@end
